home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
007
/
wasm201.arc
/
BIOS.MAC
next >
Wrap
Text File
|
1986-11-23
|
21KB
|
526 lines
List-
;============================================================================;
; Bios Macro Interface ;
; ;
; The following macros provide an interface with the basic input/output ;
; system (BIOS). Routines are provided here for accessing the keyboard, ;
; screen, and printer. ;
; ;
; Parameters may be passed as registers, memory operands, and immediate ;
; data. BP should never be used to pass parameters. Each macro describes ;
; its own parameters. Only the segement registers are guaranteed to be ;
; preserved. The macros do not check to see if their arguments are valid. ;
; ;
; These macros require the macro definition IF_EXIST, found in MISC.MAC. ;
; ;
; The direct use of the BIOS provides more control over i/o fuctions and ;
; usually a faster response time. Some functions cannot be carried out ;
; without using the BIOS. But note that a program that uses the BIOS may ;
; not be compatible with all computers now or in the future. It's usually ;
; better, where possible, to use operating system (DOS) calls. The file ;
; DOS.MAC provides similar routines using DOS. ;
; ;
; The defined macros are: ;
; ;
; BIOS_KEYBOARD_INPUT input a keystroke (1) ;
; BIOS_KEYBOARD_STATUS return the keyboard status (1) ;
; BIOS_SHIFT_STATUS return the keyboard shift status ;
; BIOS_BELL sound the speaker (1) ;
; BIOS_CLEAR_SCREEN clear the screen and home the cursor (2) ;
; BIOS_VIDEO return the present video state ;
; BIOS_VIDEO_MODE set the video mode (2) ;
; BIOS_PAGE set the active display page ;
; BIOS_CURSOR_SHAPE set the cursor shape ;
; BIOS_CURSOR_MOVE move the cursor (2) ;
; BIOS_CURSOR_POSITION return the cursor position (2) ;
; BIOS_DISPLAY display a character (1) ;
; BIOS_TYPE type a character (1) ;
; BIOS_SCROLL scroll a display window ;
; BIOS_PRINTER_STATUS return the printer status ;
; BIOS_PRINTER_RESET reset the printer ;
; ;
; (1) Function can be implemented directly through DOS. ;
; (2) Function can be implemented through DOS via ANSI escape sequences. ;
;============================================================================;
;===============================================;
; Bios_Keyboard_Input ;
; ;
; Return the next key in keyboard beffer. If ;
; none available, wait for one. AL returns the ;
; ASCII code and AH returns the keyboard scan ;
; code. ;
; ;
; ASCII - optional storage for the ASCII code ;
; returned: 8 bit register or memory. ;
; SCAN - optional storage for the scan code ;
; returned: 8 bit register or memory. ;
;===============================================;
Bios_Keyboard_Input Macro Ascii, Scan
Sub Ah, Ah ;function number
Int 16h ;execute
If_Exist Ascii
Mov Ascii, Al ;save ascii code
Endif
If_Exist Scan
Mov Scan, Ah ;save scan code
Endif
Endm
;===============================================;
; Bios_Keyboard_Status ;
; ;
; Return the keyboard status. Zero flag is set ;
; if there are no characters waiting, otherwise ;
; the zero flag is cleared and AL returns the ;
; ASCII code and AH returns the keyboard scan ;
; code of the key that is waiting (without ;
; removing it from the buffer). ;
; ;
; ASCII - optional storage for the ASCII code ;
; of next key in buffer: 8 bit register or ;
; memory. ;
; SCAN - optional storage for the scan code ;
; or next key in buffer: 8 bit register or ;
; memory. ;
;===============================================;
Bios_Keyboard_Status Macro Ascii, Scan
Mov Ah, 1 ;function number
Int 16h ;execute
If_Exist Ascii
Mov Ascii, Al ;save ascii code
Endif
If_Exist Scan
Mov Scan, Ah ;save scan code
Endif
Endm
;===============================================;
; Bios_Shift_Status ;
; ;
; Return the present keyboard shift status. AL ;
; returns the status. ;
; ;
; STATUS - optional storage for the shift ;
; status: 16 bit register or memory. ;
;===============================================;
Bios_Shift_Status Macro Status
Mov Ah, 2 ;function number
Int 16h ;execute
If_Exist Status
Mov Status, Al ;store shift status
Endif
Endm
;===============================================;
; Bios_Bell ;
; ;
; Sound the speaker. Prints a byte 7 with the ;
; bios teletype function. ;
;===============================================;
Bios_Bell Macro
Bios_Type 7 ;teletype ascii 7
Endm
;===============================================;
; Bios_Clear_Screen ;
; ;
; Clear the active screen, move the cursor to ;
; the upper left corner, and return information ;
; about the present video setup. ;
; ;
; ATTRIBUTE - optional attribute to be used in ;
; cleared screen: 8 bit register or immediate ;
; data. ;
; MODE - optional storage for the video mode: ;
; 8 bit register or memory. ;
; COLUMNS - optional storage for the number of ;
; columns: 8 bit register or memory. ;
; PAGE - optional storage for the active page: ;
; 8 bit register or memory. ;
; ;
; If attribute is not specified, the "normal" ;
; attribute of 07H will be used. ;
;===============================================;
Bios_Clear_Screen Macro Attribute, Mode, Columns, Page
Bios_Video Mode, Columns, Page ;set video info and get columns
Push Bx
If_Exist Attribute
Bios_Scroll 0, 0, 24, Ah, 0, Attribute ;clear screen
Else
Bios_Scroll 0, 0, 24, Ah, 0, 07h ;clear screen
Endif
Pop Bx
Bios_Cursor_Move 0, 0, Bh ;move cursor home
Endm
;===============================================;
; Bios_Video ;
; ;
; Bios video state. AL returns video mode, AH ;
; number of screen columns, and BH active page. ;
; ;
; MODE - optional storage for the video mode: ;
; 8 bit register or memory. ;
; COLUMNS - optional storage for the number of ;
; columns: 8 bit register or memory. ;
; PAGE - optional storage for the active page: ;
; 8 bit register or memory. ;
;===============================================;
Bios_Video Macro Mode, Columns, Page
Mov Ah, 15 ;function number
Int 10h ;execute
If_Exist Mode
Mov Mode, Al ;save mode
Endif
If_Exist Columns
Mov Columns, Ah ;save columns
Endif
If_Exist Page
Mov Page, Bh ;save page
Endif
Endm
;===============================================;
; Bios_Video_Mode ;
; ;
; Set video mode. ;
; ;
; MODE - video mode to set: 8 bit operand. ;
;===============================================;
Bios_Video_Mode Macro Mode
Mov Al, Mode ;set mode
Sub Ah, Ah ;function number
Int 10h ;execute
Endm
;===============================================;
; Bios_Page ;
; ;
; Set active display page. Monochrome adapter ;
; has only one page (0). CGA and EGA vary ;
; according to mode. The present active page ;
; can be found with BIO_VIDEO. ;
; ;
; PAGE - display page to activate: 8 bit ;
; operand. ;
;===============================================;
Bios_Page Macro Page
Mov Al, Page ;page
Mov Ah, 5 ;function number
Int 10h ;execute
Endm
;===============================================;
; Bios_Cursor_Kill ;
; ;
; Try to make the cursor disappear by moving it ;
; off the screen. ;
;===============================================;
Bios_Cursor_Kill Macro
Bios_Cursor_Move 255, 255, 0
Endm
;===============================================;
; Bios_Cursor_Shape ;
; ;
; Set the shape of the cursor. A monochrome ;
; adapter cursor has 14 scan lines (0 to 13) ;
; and CGA has 8 (0 to 7). ;
; ;
; START - starting scan line number: 8 bit ;
; register or immediate data. ;
; END - ending scan line number: 8 bit register ;
; or immediate data. ;
;===============================================;
Bios_Cursor_Shape Macro Start, End
Push Cx ;parameters on stack
Mov Bp, Sp
Mov Byte [Bp+1], Start ;starting line
Mov Byte [Bp], End ;finishing line
Pop Cx ;restore parameters
Mov Ah,1 ;function number
Int 10h ;execute
Endm
;===============================================;
; Bios_Cursor_Move ;
; ;
; Move the cursor. ;
; ;
; ROW - row position: 8 bit register or ;
; immediate data. ;
; COLUMN - column position: 8 bit register or ;
; immediate data. ;
; PAGE - display page (must be zero in graphics ;
; mode): 8 bit register or immediate data. ;
; ;
; A cursor position is maintained for each ;
; display page. If a page is not specified, ;
; the routine will get the active page via a ;
; BIOS_VIDEO call. The first row or column is ;
; zero. ;
;===============================================;
Bios_Cursor_Move Macro Row, Column, Page
Push Bx
Push Dx
Mov Bp, Sp
Mov Byte [Bp+1], Row ;row
Mov Byte [Bp], Column ;column
If_Exist Page
Mov Byte [Bp+3], Page ;page
Else
Push Ax
Push Bx
Push Cx
Push Dx
Push Di
Push Si
Push Bp
Bios_Video ;get page
Pop Bp
Mov [Bp+3], Bh ;set page
Pop Si
Pop Di
Pop Dx
Pop Cx
Pop Bx
Pop Ax
Endif
Pop Dx
Pop Bx ;restore parameters
Mov Ah,2 ;function number
Int 10h ;execute
Endm
;===============================================;
; Bios_Cursor_Position ;
; ;
; Return the present cursor position. ;
; ;
; ROW - optional storage for the row: 8 bit ;
; register or memory. ;
; COLUMN - optional storage for the column: 8 ;
; bit register or memory. ;
; PAGE - display page (must be zero in graphics ;
; mode): 8 bit register or immediate data. ;
; ;
; A cursor position is maintained for each ;
; display page. If a page is not specified, ;
; the routine will get the active page via a ;
; BIOS_VIDEO call. The first row or column is ;
; considered zero. ;
;===============================================;
Bios_Cursor_Position Macro Row, Column, Page
If_Exist Page
Mov Bh, Page ;set page
Else
Bios_Video ;get page (returns in BH)
Endif
Mov Ah, 3 ;function number
Int 10h ;execute
If_Exist Row
Mov Row, Dh ;save row
Endif
If_Exist Column
Mov Column, Dl ;save column
Endif
Endm
;===============================================;
; Bios_Display ;
; ;
; Bios character display. The cursor is not ;
; moved and no interpretation takes place. ;
; ;
; CHAR - character to display: 8 bit register ;
; or immediate data. ;
; COLOR - optional attribute to display the ;
; character with: 8 bit register or immediate ;
; data. ;
; COUNT - optional number of characters to ;
; display: 8 bit register or immediate data. ;
; PAGE - optional page number in which to ;
; display characters: 8 bit register or ;
; immediate data. ;
; ;
; If a page is not specified, the routine will ;
; get the page via a BIOS_VIDEO call. ;
;===============================================;
Bios_Display Macro Char, Color, Count, Page
Push Ax
Push Bx
Push Cx ;parameters on stack
Mov Bp, Sp
Mov Byte [Bp+4], Char ;character to display
If_Exist Color
Mov Byte [Bp+2], Color ;attribute
Endif
If_Exist Page
Mov Byte [Bp+3], Page ;page
Else
Push Ax ;save all regs, might be needed
Push Bx
Push Cx
Push Dx
Push Di
Push Si
Push Bp
Bios_Video ;get page
Pop Bp
Mov [Bp+3], Bh ;set page
Pop Si
Pop Di
Pop Dx
Pop Cx
Pop Bx
Pop Ax
Endif
If_Exist Count
If Size(Count) And Size(Ax)
Mov Word [Bp], Count ;set count
Else
Mov Byte [Bp], Count ;set low count byte
Mov Byte [Bp+1], 0 ;high byte 0
Endif
Else
Mov Word [Bp], 1 ;no count, set to one
Endif
Pop Cx
Pop Bx
Pop Ax ;restore parameters
If_Exist Color
Mov Ah, 9 ;display with attribute
Else
Mov Ah, 10 ;display without attribute
Endif
Int 10h ;execute
Endm
;===============================================;
; Bios_Type ;
; ;
; Bios teletype. Cursor is moved and CR, LF, ;
; BS, and BEL are interpreted. ;
; ;
; CHAR - character to display: 8 bit register ;
; or immdiate data. ;
; COLOR - foreground color (valid only in ;
; graphics mode): 8 bit register or immediate ;
; data. ;
;===============================================;
Bios_Type Macro Char, Color
Push Ax ;parameters on stack
Mov Bp, Sp
Mov Byte [Bp], Char ;character to display
If_Exist Color
Mov Bl, Color ;set color
Endif
Pop Ax ;restore parameters
Mov Ah, 14 ;function number
Int 10h ;execute
Endm
;===============================================;
; Bios_Scroll ;
; ;
; Clear or scroll a display window up. A scroll ;
; of zero clears window. ;
; ;
; START_ROW - upper left row coordinate: 8 bit ;
; register or immediate data. ;
; START_COL - upper left column coordinate: 8 ;
; bit register or immediate data. ;
; END_ROW - lower right row coordinate: 8 bit ;
; register or immediate data. ;
; END_COL - lower right column coordinate: 8 ;
; bit register or immediate data. ;
; LINES - number of lines to scroll up (zero if ;
; clear window): 8 bit register or immediate ;
; data. ;
; ATTRIBUTE - attribute to use in blanked ;
; areas: 8 bit register or immediate data. ;
; ;
; The first row or column is zero. ;
;===============================================;
Bios_Scroll Macro Start_Row, Start_Col, End_Row, End_Col, Lines, Attribute
Push Ax ;parameters on stack
Push Cx
Push Dx
Mov Bp, Sp
Mov Byte [Bp+3], Start_Row ;upper left row
Mov Byte [Bp+2], Start_Col ;upper left column
Mov Byte [Bp+1], End_Row ;lower right row
Mov Byte [Bp], End_Col ;lower right column
Mov Byte [Bp+4], Lines ;lines to scroll
Mov Byte [Bp+5], Attribute ;attribute to use in blanks
Pop Dx
Pop Cx
Pop Ax
Mov Bh, Ah ;set attibute register
Mov Ah, 6 ;function number
Int 10h ;execute
Endm
;===============================================;
; Bios_Printer_Status ;
; ;
; Return the status of a parallel printer. AH ;
; returns status. ;
; ;
; PRINTER - printer number: 16 bit operand. ;
; STATUS - optional storage for printer status: ;
; 8 bit register or memory. ;
; ;
; The printers are numbered 0 to 2. ;
;===============================================;
Bios_Printer_Status Macro Printer, Status
Mov Dx, Printer ;set printer number
Mov Ah, 2 ;function number
Int 17h ;execute
If_Exist Status
Mov Status, Ah ;store status
Endif
Endm
;===============================================;
; Bios_Printer_Reset ;
; ;
; Initialize a parallel printer port. AH ;
; returns status. ;
; ;
; PRINTER - printer number to initialize: 16 ;
; bit operand. ;
; STATUS - optional storage for printer status: ;
; 8 bit register or memory. ;
; ;
; The printers are numbered 0 to 2. ;
;===============================================;
Bios_Printer_Reset Macro Printer, Status
Mov Dx, Printer ;set printer number
Mov Ah, 1 ;function number
Int 17h ;execute
If_Exist Status
Mov Status, Ah ;store status
Endif
Endm